const path = require('path')
const webpack = require('webpack')
const merge = require('webpack-merge')
const commonConfig = require('./webpack.config.common')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const devConfig = {
  devtool: 'eval-source-map',
  mode: 'development', // 'development' 和 'production'
  entry: { app: path.resolve(__dirname, '../src/index.tsx') },

  devServer: {
    host: 'localhost',
    open: true, // 当webpackDevServer启动时,会自动帮我们打开浏览器,并访问服务器的地址
    stats: 'errors-only',
    // 跨域配置
    // proxy: {
    //   '/api': {
    //     target: 'https://test-mws.dn8188.com',
    //     changeOrigin: true
    //   },
    //   '/stock': {
    //     target: 'https://test-mws.dn8188.com',
    //     changeOrigin: true
    //   }
    // },
    port: 8001,
    hot: true, // 让webpack-dev-server开启HotModuleReplacement功能
    historyApiFallback: true // 解决单页面应用路由问题
  },

  // 在development模式下开启treeshaking
  optimization: {
    usedExports: true
  },

  plugins: [
    new ReactRefreshPlugin(),
    new ForkTsCheckerWebpackPlugin({
      async: false
    })
  ]
}
module.exports = merge(commonConfig, devConfig)
